package health.lm.com.find.fragment;

import android.os.Bundle;
import android.support.v4.view.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.androidkun.xtablayout.XTabLayout;

import java.util.List;

import butterknife.BindView;
import health.lm.com.component_base.base.mvp.fragment.XLazyFragment;
import health.lm.com.find.R;
import health.lm.com.find.R2;
import health.lm.com.find.adapter.HActivityPagerAdapter;
import health.lm.com.find.entity.HActivityEntity;
import health.lm.com.find.presenter.HActivityPresenter;

/**
 * 链活动
 * @author GQI
 */
public class HActivityFragment extends XLazyFragment<HActivityPresenter> {
    @BindView(R2.id.xTablayout)
    XTabLayout xTablayout;
    @BindView(R2.id.viewPager)
    ViewPager viewPager;
    private List<HActivityEntity.Category_list> entities;
    private String id;


    @Override
    public int getLayoutId() {
        return R.layout.fragment_h_activity;
    }

    @Override
    public HActivityPresenter newP() {
        return new HActivityPresenter();
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        Bundle bundle = getArguments();
        if (bundle != null) {
            id = bundle.getString("id");
        }
        getP().getColumn();
    }

    public static HActivityFragment getInstance(String id) {
        HActivityFragment fragment = new HActivityFragment();
        Bundle args = new Bundle();
        args.putSerializable("id", id);
        fragment.setArguments(args);
        return fragment;
    }

    public void getColumn(List<HActivityEntity.Category_list> entities) {
        this.entities = entities;
        HActivityPagerAdapter adapter = new HActivityPagerAdapter(getChildFragmentManager(), entities);
        viewPager.setAdapter(adapter);
        viewPager.setOffscreenPageLimit(3);
        xTablayout.setxTabDisplayNum(entities.size());
        //将TabLayout和ViewPager关联起来。
        xTablayout.setupWithViewPager(viewPager);
    }

}
